#!/bin/sh

main=../game

graphType=$1
N=$2
z=$3
initialCoop=$4
gameType=$5
paramLow=$6
paramStep=$7
paramHigh=$8
nIterations=$9
nRuns=${10}

nParams=`seq $paramLow $paramStep $paramHigh | wc -l`

cmdBase="$main --graphType=$graphType --N=$N --z=$z --initialCooperativity=$initialCoop --gameType=$gameType --iterations=$nIterations"

function dumpScalar {
	name=$1
	value=$2
	echo "# name: $name"
	echo "# type: scalar"
	echo "$value"
}

function dumpString {
	name=$1
	value=$2
	length=`echo -e $value | wc -c`
	echo "# name: $name"
	echo "# type: string"
	echo "# elements: 1"
	echo "# length: $length"
	echo "$value"
}

function dumpMatrixHeader {
	name=$1
	nx=$2
	ny=$3
	echo "# name: $name"
	echo "# type: matrix"
	echo "# rows: $nx"
	echo "# columns: $ny"
}

function dump3DMatrixHeader {
	name=$1
	nx=$2
	ny=$3
	nz=$4
	echo "# name: $name"
	echo "# type: matrix"
	echo "# ndims: 3"
	echo "$nx $ny $nz"
}

dir="data"
file="$dir/data_${gameType}_${graphType}_${nIterations}_${nRuns}_${N}_${z}"

echo    "# Octave data file that holds simulation data"  > $file
echo -n "# Created on " >> $file
date >> $file

dumpString "graphType" 		"$graphType"	>> $file
dumpString "gameType"		"$gameType"	>> $file
dumpScalar "nNodes"		$N		>> $file
dumpScalar "averageDegree"	$z		>> $file
dumpScalar "initialCoop"	$initialCoop	>> $file
dumpScalar "paramLow"		$paramLow	>> $file
dumpScalar "paramStep"		$paramStep	>> $file
dumpScalar "paramHigh"		$paramHigh	>> $file
dumpScalar "nIterations"	$nIterations	>> $file
dumpScalar "nRuns" 		$nRuns		>> $file



dumpMatrixHeader "params" $nParams 1 >> $file
seq $paramLow $paramStep $paramHigh >> $file


dump3DMatrixHeader "cooperativities" $nIterations $nRuns $nParams >> $file
for param in `seq $paramLow $paramStep $paramHigh`
do
	thisParamFile=${file}_${param}
	for run in `seq 1 $nRuns`
	do
		echo "param = $param, run $run of $nRuns"
		cmd="$cmdBase --b=$param --r=$param"

		$cmd >> ${file}
	done
done

